package com.fdd.op.demo;

import com.fdd.op.sdk.ApiException;
import com.fdd.op.sdk.DefaultFddClient;
import com.fdd.op.sdk.constants.Constants;
import com.fdd.op.sdk.internal.token.FddTokenStore;
import com.fdd.op.sdk.internal.token.stroe.CacheTokenStoreImpl;
import com.fdd.op.sdk.model.dto.DocInfoDTO;
import com.fdd.op.sdk.model.dto.PersonQuickSignInfoDTO;
import com.fdd.op.sdk.request.api.contract.CheckSignatureRequest;
import com.fdd.op.sdk.request.api.contract.sign.PersonQuickSignRequest;
import com.fdd.op.sdk.response.api.contract.CheckSignatureResponse;
import com.fdd.op.sdk.response.api.contract.sign.PersonQuickSignResponse;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @description: 定制-发起合同并推送签署--个人快捷签署
 * @author lijiaxin@fadada.com
 * @date 2023/8/23 14:04
 */
public class PersonQuickSignApi {
    private static String serverUrl = "http://10.21.8.20:37801/";
    private static final String appId = "486478";
    private static final String appKey = "xguUMVFnDzqJgfVEDnLW16yE2mxVL2Fp";

    public static void main(String[] args) throws ApiException {
        FddTokenStore tokenStore = new CacheTokenStoreImpl();
        DefaultFddClient fddClient = new DefaultFddClient(serverUrl, appId, appKey, Constants.AUTH_OAUTH, 1000, 30000);
        fddClient.tokenStore(tokenStore);
        PersonQuickSignRequest request = new PersonQuickSignRequest();
        request.setDocTitle("《测试合同》2233222");
        request.setSignDocType(1);
        request.setIsAutoArchive(1);
        request.setIsPagePosition(0);
        request.setSenderAccountId("1683413560658190337");
        request.setCompanyId("1683413561908092929");
        request.setCompanyName("");
        request.setIsSort(0);
        request.setNotifyUrl("https://webhook.site/398efbd9-bdaf-4f2b-9246-bdd95c342b9c");
        List<DocInfoDTO> docList = new ArrayList<>();
        DocInfoDTO docInfoDTO = new DocInfoDTO();
        docInfoDTO.setFileId("20230824_contractPdf_349990905803116544");
        docList.add(docInfoDTO);
        request.setDocList(docList);

        List<PersonQuickSignInfoDTO> signerInfos = new ArrayList<>();
        PersonQuickSignInfoDTO infoDTO = new PersonQuickSignInfoDTO();
        infoDTO.setIsSendNotify(0);
        infoDTO.setNotifyNo("1122114733");
        infoDTO.setPriority(1);
        infoDTO.setSignType(0);
        infoDTO.setSignMode(1);
        infoDTO.setVerifyMode("1");
        infoDTO.setMobile("15511001102");
        infoDTO.setSignerName("张三");
        infoDTO.setIdCard("110101198507281010");
        infoDTO.setIsPosition(0);
        infoDTO.setFailUrl("https://www.fadada.com");
        infoDTO.setRedoNum(4);
        infoDTO.setReturnUrl("https://www.baidu.com");
        signerInfos.add(infoDTO);
        request.setSignerInfos(signerInfos);
        PersonQuickSignResponse response = fddClient.execute(request);
        if(response != null && "0".equals(response.getCode())){
            System.out.println(response.getData());
        }
    }
}
